#-*- coding: UTF-8 -*-
import urllib
import re
from  urllib import request

target = "http://jandan.net/ooxx/page-249#comments"
imgNum = 0

def getHtml(url):
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    page = urllib.request.Request(url=url, headers=headers)
    html=urllib.request.urlopen(page).read()
    html = html.decode('utf-8')
    return html

def changeImg(x):
    # return target+x
    return "http:"+x
    # return x

def getImg(html):
    global imgNum
    reg = r'src="(.*\.jpg)"'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    imglist=list(map(changeImg, imglist))
    print(imglist)
    x = 0
    for imgurl in imglist:
        urllib.request.urlretrieve(imgurl,'d:/imgs/%s.jpg' % imgNum)
        imgNum+=1
    return imglist



# html=getHtml(target)
# print (getImg(html))
249
tar1 = "http://jandan.net/ooxx/page-"
tar2 = "#comments"
for x in range(1, 249):
    target = tar1+str(x)+tar2
    html=getHtml(target)
    print (getImg(html))
